﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="attendpaper.aspx.cs" Inherits="OnlineTestUI.attendpaper" %>

<%@ Import Namespace="OnlineTestModel" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="Scripts/json2.js"></script>
    <script type="text/javascript">
        function intToLetter(id) {
            var str = "";
            if (Math.floor((id / 65)) != 0) {
                str = String.fromCharCode(id);//65 代表'A'的ASCII值.
            }
            //String.fromCharCode(num):求出num数值对应的字母.num应该为ASCII中的值.
            return str;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server" onsubmit="getPaper()" method="post">
        <f:PageManager ID="PageManager1" AutoSizePanelID="RegionPanel1" runat="server"></f:PageManager>
        <%=p.PaperName %>
        <div>
            <% for (int i = 0; i < pqeList.Count; i++)
               {
                   PaperQuestionEx item = pqeList[i];
                   switch (item.QuestionTypeId)
                   {
                       case 1:%><div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                           <input class="questiontype" type="hidden" value="<%=item.QuestionTypeId %>" />
                           <div class="div_preview">
                               <div class="div_title_question_all">
                                   <div class="div_topic_question">1.<%=item.BigQuestion%><%=item.SmallQuestion%></div>
                                   <div class="div_title_question"><span><%=item.QuestionName%></span></div>
                                   <div style="clear: both;"></div>
                               </div>
                               <div class="div_table_radio_question">
                                   <div class="div_table_clear_top"></div>
                                   <ul>
                                       <% int n = 0;foreach (var questionItem in qib.GetModelList("questionid =" + item.QuestionId))
                                         {%><li style="width: 99%;">
                                             <input type="radio" data-score="<%=item.Score%>" class="" name="<%=item.QuestionId%>" data-letter="<%=n+65 %>" /><%=questionItem.ItemName%></li>
                                       <%
                                             n++;
                                         }%>

                                       <div style="clear: both;"></div>
                                   </ul>
                                   <div class="div_table_clear_bottom"></div>
                               </div>

                               <div style="clear: both;"></div>
                           </div>
                       </div>
            <%; break;
                       case 2:%><div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                           <input class="questiontype" type="hidden" value="<%=item.QuestionTypeId %>" />
                           <div class="div_preview">
                               <div class="div_title_question_all">
                                   <div class="div_topic_question">1.</div>
                                   <div class="div_title_question"><span><%=item.QuestionName%></span></div>
                                   <div style="clear: both;"></div>
                               </div>
                               <div class="div_table_radio_question">
                                   <div class="div_table_clear_top"></div>
                                   
                                       <input id="<%=item.QuestionId%>" data-score="<%=item.Score%>" name="<%=item.QuestionId%>" type="text" />

                                       <div style="clear: both;"></div>
                                  
                                   <div class="div_table_clear_bottom"></div>
                               </div>


                               <div style="clear: both;"></div>
                           </div>
                       </div>
            <%; break;
                       case 3:%><div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                           <input class="questiontype" type="hidden" value="<%=item.QuestionTypeId %>" />
                           <div class="div_preview">
                               <div class="div_title_question_all">
                                   <div class="div_topic_question">1.</div>
                                   <div class="div_title_question"><span><%=item.QuestionName%></span></div>
                                   <div style="clear: both;"></div>
                               </div>
                               <div class="div_table_radio_question">
                                   <div class="div_table_clear_top"></div>
                                   <ul>
                                       <input type="radio" data-score="<%=item.Score%>" name="<%=item.QuestionId%>" value="正确" />
                                       正确
                                                      <br />
                                       <input type="radio" data-score="<%=item.Score%>" name="<%=item.QuestionId%>" value="错误" />
                                       错误

                                                      <div style="clear: both;"></div>
                                   </ul>
                                   <div class="div_table_clear_bottom"></div>
                               </div>
                               <div class="div_ins_question"></div>
                               <div style="clear: both;"></div>
                           </div>
                       </div>
            <%; break;
                       case 4:%><div style="visibility: visible;" tabindex="-1" class="div_question div_question_mouseout">
                           <input class="questiontype" type="hidden" value="<%=item.QuestionTypeId %>" />
                           <div class="div_preview">
                               <div class="div_title_question_all">
                                   <div class="div_topic_question">1.</div>
                                   <div class="div_title_question"><span><%=item.QuestionName%></span></div>
                                   <div style="clear: both;"></div>
                               </div>
                               <div class="div_table_radio_question">
                                   <div class="div_table_clear_top"></div>
                                   <ul>
                                       <textarea class="inputtext" data-score="<%=item.Score%>" name="<%=item.QuestionId%>" style="width: 62%; height: 90px; overflow: auto;" rows="1" wrap="soft"></textarea>

                                       <div style="clear: both;"></div>
                                   </ul>
                                   <div class="div_table_clear_bottom"></div>
                               </div>
                               <div class="div_ins_question"></div>

                               <div style="clear: both;"></div>
                           </div>
                       </div>
            <%; break;
                   }
               }%>
            
        </div>
       
        <input id="paperresult" type="hidden" name="paperresult" />
        <asp:Button ID="Button2" runat="server" Text="提交答卷" OnClick="BtAdd_Click" />
        
        <script type="text/javascript">
            function getPaper() {
                var paper = { "question": [] };
                $(".div_question").each(function (n) {
                    var questiontype = $(".div_question:eq(" + n + ") .questiontype").val();
                    var questionid;
                    var answer;
                    var newquestion;
                    switch (questiontype) {
                        case "1":
                            var checks1 = $(".div_question:eq(" + n + ") input[type='radio']");
                            var i = 0;//标志是否做了此题
                            checks1.each(function (m) {
                                var _this = $(this);
                                var isc = _this.is(':checked');
                                
                                questionid = _this.attr('name');
                                score = _this.data('score');
                                if (isc)//选中要处理的
                                {
                                    i++;
                                    answer = intToLetter(_this.data('letter'));
                                    newquestion = { "paperid": "<%=p.Id%>", "studentid": "<%=s.Id%>", "questionid": questionid, "answer": answer, "questiontypeid": questiontype, "score": score };
                                    paper.question.push(newquestion);
                                }
                                if (i === 0&&m===3) {
                                    answer = 0;//未答此题
                                    newquestion = { "paperid": "<%=p.Id%>", "studentid": "<%=s.Id%>", "questionid": questionid, "answer": answer, "questiontypeid": questiontype, "score": score };
                                    paper.question.push(newquestion);
                                }
                                
                            });
                            


                            break;
                        case "2":
                            var checks2 = $(".div_question:eq(" + n + ") input[type='text']");
                            var _this = $(checks2[0]);
                           
                            questionid = _this.attr("name");
                            answer = _this.val();
                            score = 0;
                            newquestion = { "paperid": "<%=p.Id%>", "studentid": "<%=s.Id%>", "questionid": questionid, "answer": answer, "questiontypeid": questiontype, "score": score };
                            paper.question.push(newquestion);
                            break;
                        case "3":
                            var checks3 = $(".div_question:eq(" + n + ") input[type='radio']");
                            checks3.each(function () {
                                var _this = $(this);
                                
                                questionid = _this.attr("name");
                                score = _this.data('score');
                                var isc = $(this).is(':checked');
                                if (isc)//选中要处理的
                                {
                                    answer = _this.val();
                                } else {
                                    answer = 0;//未答此题
                                }
                                if (isc)//选中要处理的
                                {
                                    newquestion = { "paperid": "<%=p.Id%>", "studentid": "<%=s.Id%>", "questionid": questionid, "answer": answer, "questiontypeid": questiontype, "score": score };
                                    paper.question.push(newquestion);
                                }

                            });
                            break;
                        case "4":
                            var checks4 = $(".div_question:eq(" + n + ") textarea");
                            var _this = $(checks4[0]);
                            
                            questionid = _this.attr("name");
                            answer = _this.val();
                            score = 0;
                            newquestion = { "paperid": "<%=p.Id%>", "studentid": "<%=s.Id%>", "questionid": questionid, "answer": answer, "questiontypeid": questiontype, "score": score };
                            paper.question.push(newquestion);
                            break;
                    }


                });
                var paperstring = JSON.stringify(paper);//将对象转换为字符串
                $(" #paperresult").val(paperstring);
            }

        </script>
    </form>
</body>
</html>
